package com.kk.hystrix.service;

import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixProperty;
import org.springframework.stereotype.Service;

import java.util.concurrent.TimeUnit;

/**
 * the type of springcloud-alibaba
 *
 * <p>
 * .
 *
 * @author 王志强
 * @date 2022-11-16
 */
@Service
public class HystrixService {

    /** 服务降级，超时或者报错调用兜底方法 */
    @HystrixCommand(fallbackMethod = "pocketBottom", commandProperties = {
            @HystrixProperty(name = "execution.isolation.thread.timeoutInMilliseconds", value = "3000")
    })
    public String normal() {
        try {
            int i = 1/0;
            TimeUnit.SECONDS.sleep(5);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        return "O(∩_∩)O哈哈  成功啦！";
    }

    public String abnormal() {
        return "┭┮﹏┭┮  失败啦！";
    }

    public String pocketBottom() {
        return "服务调用的方法超时或报错了，调用爹来兜底！";
    }
}
